package com.cghs.ac.info;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;

public class ApkInfoUtils {
	/**
	 * 获取当前版本号
	 * @param context
	 * @return int 版本号 如 1211
	 */
	public static int getVersionCode(Context context) {
		 try {  
	            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);  
	            int localVersionCode = packageInfo.versionCode;  
	            return localVersionCode;
	        } catch (NameNotFoundException e) {  
	            e.printStackTrace();  
	        } 
		 return -1;
	}
	
	/**
	 * 获取当前版本字符串
	 * @param context
	 * @return String  版本 如 v1.2.11
	 */
	public static String getVersionName(Context context) {
		 try {  
	            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);  
	            String localVersionName = packageInfo.versionName;  
	            return localVersionName;
	        } catch (NameNotFoundException e) {  
	            e.printStackTrace();  
	        } 
		 return null;
	}
}
